import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

/**
 * @Author 12629
 * @Description：
 */
class Student /*implements Comparable<Student>*/{
    public int age;

    public Student(int age) {
        this.age = age;
    }
   /* @Override
    public int compareTo(Student o) {
        return this.age-o.age;
    }*/
}
class AgeComparator implements Comparator<Student> {

    @Override
    public int compare(Student o1, Student o2) {
        return o2.age-o1.age;
    }
}
public class Test {

    public static void main(String[] args) {
        TestHeap testHeap = new TestHeap();
        int[] array = {27,15,19,18};
        testHeap.initArray(array);

        testHeap.createHeap();

        testHeap.heapSort();

        System.out.println("dddddd");
    }

    public static void topK1(int[] array,int k) {
        PriorityQueue<Integer> maxPQ = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });

        for (int i = 0; i < array.length; i++) {
            maxPQ.offer(array[i]);
        }

        for (int i = 0; i < k; i++) {
            int val = maxPQ.poll();
            System.out.println(val);
        }
    }

    public static int[] topK2(int[] array,int k) {
        PriorityQueue<Integer> maxPQ = new PriorityQueue<>(k,new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });

        for (int i = 0; i < array.length; i++) {
            if(maxPQ.size() < k) {
                maxPQ.offer(array[i]);
            }else {
                //获取到堆顶元素
                int top = maxPQ.peek();
                //找前k个最小的
                if(array[i] < top) {
                    maxPQ.poll();
                    maxPQ.offer(array[i]);
                }
            }
        }
        int[] ret = new int[k];
        for (int i = 0; i < k; i++) {
            ret[i] = maxPQ.poll();
        }
        return ret;
    }

    public static int[] topK3(int[] array,int k) {
        PriorityQueue<Integer> maxPQ = new PriorityQueue<>(k,new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });


        for (int i = 0; i < k; ++i) {
            maxPQ.offer(array[i]);
        }

        for (int i = k; i < array.length; i++) {
            //获取到堆顶元素
            int top = maxPQ.peek();
            //找前k个最小的
            if(array[i] < top) {
                maxPQ.poll();
                maxPQ.offer(array[i]);
            }
        }
        int[] ret = new int[k];
        for (int i = 0; i < k; i++) {
            ret[i] = maxPQ.poll();
        }
        return ret;
    }

    public static void main5(String[] args) {
        int[] array = {12,45,32,17,2,18,5,10};
        topK1(array,3);
    }

    public static void main4(String[] args) {
        Student student1 = new Student(5);
        Student student2 = new Student(15);

        AgeComparator ageComparator = new AgeComparator();
        PriorityQueue<Student> priorityQueue = new PriorityQueue<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.age-o2.age;
            }
        });

        PriorityQueue<Student> priorityQueue2 = new PriorityQueue<>((o1,o2)-> o1.age- o2.age);
        priorityQueue.offer(student1);
        priorityQueue.offer(student2);
        System.out.println("fdfadsa");
        //priorityQueue.offer(null);


    }

    public static void main3(String[] args) {
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        priorityQueue.offer(12);
        priorityQueue.offer(5);
        priorityQueue.offer(42);
        priorityQueue.offer(8);
        System.out.println(priorityQueue.peek());
        System.out.println(priorityQueue.poll());
    }


    public static void main2(String[] args) {
        TestHeap testHeap = new TestHeap();
        int[] array = {27,15,19,18,28,34,65,49,25,37};
        testHeap.initArray(array);

        testHeap.createHeap();

        testHeap.poll();

        System.out.println("fafsafdsfsafdsfa");

    }

    public void merge(int A[], int m, int B[], int n) {
        int i = m-1;
        int j = n-1;
        int k = m+n-1;

        while (i >= 0 && j >= 0) {
            if(B[j] >= A[i]) {
                A[k] = B[j];
                k--;
                j--;
            }else {
                A[k] = A[i];
                k--;
                i--;
            }
        }

        while (i >= 0) {
            A[k] = A[i];
            k--;
            i--;
        }

        while (j >= 0) {
            A[k] = B[j];
            k--;
            j--;
        }
    }


    public static String func(String str) {
        //int[] array = new int[255];
        boolean[] flg = new boolean[255];
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);
            if(flg[ch] == false) {
                stringBuilder.append(ch);
                flg[ch] = true;
            }
        }
        return stringBuilder.toString();
    }

    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()) {
            String str = scanner.nextLine();
            String ret = func(str);
            System.out.println(ret);
        }
    }
}
